﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace Is.Core
{
    internal class IsEqualityComparer<T> : IEqualityComparer<T>
    {
        public bool Equals(T x, T y)
        {
            Type type = typeof(T);

            if (Is.IsNullable<T>())
            {
                if (x == null)
                {
                    return (y == null);
                }
                else if (y == null)
                {
                    return false;
                }
            }

            IEnumerable enumerableX = x as IEnumerable;
            IEnumerable enumerableY = y as IEnumerable;

            if (enumerableX != null && enumerableY != null)
            {
                return new EnumerableEqualityComparer().Equals(enumerableX, enumerableY);
            }
            if (typeof(IEquatable<T>).IsAssignableFrom(type))
            {
                return ((IEquatable<T>)x).Equals(y);
            }

            return x.Equals(y);
        }

        public int GetHashCode(T obj)
        {
            throw new NotImplementedException();
        }
    }
}